#!/usr/bin/env bash
cd /var/local
if [ ! -d "./web/" ];then
  git clone https://github.com/demo2099/web.git
  else
  echo "文件夹已经存在"
fi
#rm -rf web
#git clone http://124.223.11.108:13000/demo2099/web.git
rm -rf  nginx
mkdir nginx
mkdir -p /var/local/nginx/{conf,html,logs}
touch /var/local/nginx/html/index.html
echo   "<html><body><h1> xxxxxxxxxxxxxe</h1><p>This application has no explicit mapping for /error, so you are seeing this as a fallback.</p><div id='created'>Wed Sep 09 15:07:28 CST 2020</div><div>There was an unexpected error (type=Not Found, status=404).</div><div>No message available</div></body></html>" >> /var/local/nginx/html/index.html
touch /var/local/nginx/conf/nginx.conf
cat >/var/local/nginx/conf/nginx.conf  <<EOF
user  nginx;
worker_processes  1;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    log_format  main  ' -  [] "" '
                      '  "" '
                      '"" ""';
    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    keepalive_timeout  65;

    include /etc/nginx/conf.d/*.conf;


    server {
        listen       80;
        server_name  $1;
        return 301 https://\$host\$request_uri;

    }

    server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        server_name $1;

        ssl_certificate /etc/v2ray-agent/tls/$1.crt;
        ssl_certificate_key /etc/v2ray-agent/tls/$1.key;
        ssl_protocols TLSv1.2 TLSv1.3;
        ssl_stapling on;
        ssl_stapling_verify on;

        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }

        location /love {
            proxy_redirect off;
            proxy_pass http://127.0.0.1:2222;
            proxy_http_version 1.1;
            proxy_set_header Upgrade \$http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Host \$http_host;
            proxy_set_header X-Real-IP \$remote_addr;
            proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
        }
       location /zlovenf {
            proxy_redirect off;
            proxy_pass http://72.19.12.227:28093;
            proxy_http_version 1.1;
            proxy_set_header Upgrade \$http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Host \$http_host;
        }
        location /xlovenf {
            proxy_redirect off;
            proxy_pass http://72.19.12.227:2222;
            proxy_http_version 1.1;
            proxy_set_header Upgrade \$http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Host \$http_host;
            proxy_set_header X-Real-IP \$remote_addr;
            proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
        }
        location /ylovenf {
            proxy_redirect off;
            proxy_pass http://38.96.139.236:2222;
            proxy_http_version 1.1;
            proxy_set_header Upgrade \$http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Host \$http_host;
            proxy_set_header X-Real-IP \$remote_addr;
            proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
        }
        location /lovenf {
            proxy_redirect off;
            proxy_pass http://127.0.0.1:5678;
            proxy_http_version 1.1;
            proxy_set_header Upgrade \$http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Host \$http_host;
            proxy_set_header X-Real-IP \$remote_addr;
            proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
        }
        location /lovenfsg {
            proxy_redirect off;
            proxy_pass http://127.0.0.1:33333;
            proxy_http_version 1.1;
            proxy_set_header Upgrade \$http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Host \$http_host;
            proxy_set_header X-Real-IP \$remote_addr;
            proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
    }
}
EOF
x=$[RANDOM%10+1]
echo "随机网站love${x}"
rm -rf /var/local/web/love1/*
wget -c -P /usr/share/nginx "https://raw.githubusercontent.com/mack-a/v2ray-agent/master/fodder/blog/unable/html${x}.zip" >/dev/null
unzip -o "/usr/share/nginx/html${x}.zip" -d /usr/share/nginx/html >/dev/null
rm -f "/usr/share/nginx/html${x}.zip*"
cp -r /usr/share/nginx/html/* /var/local/web/love1/
docker rm -f mynginx
docker run  -d --restart=always --name mynginx  --network host -v /etc/v2ray-agent/tls/:/etc/v2ray-agent/tls/ -v /var/local/nginx/conf/nginx.conf:/etc/nginx/nginx.conf  -v /var/local/nginx/logs:/var/log/nginx  -v /var/local/web/love1:/usr/share/nginx/html nginx